/*
 * @Description:
 * @Version: 1.0
 * @Author: biao.hu
 * @Date: 2021-10-26 21:57:46
 * @LastEditors: biao.hu
 * @LastEditTime: 2021-10-29 14:29:03
 */
package Queue

import "fmt"

type ArrayQueue struct {
	Data      []int
	MaxLength int
	Length    int
}

/**
 * @description: 入队列
 * @param {int} val
 * @return {*}
 */
func (a *ArrayQueue) Push(val int) {
	if a.Length < 0 {
		return
	}
	a.Data = append(a.Data, val)
	a.Length++
}

/**
 * @description: 出队列
 * @param {*}
 * @return {int}
 */
func (a *ArrayQueue) Pop() int {
	if a.Length == 0 {
		return 0
	}

	pop := a.Data[0]
	count := 0
	for count < a.Length-1 {
		a.Data[count] = a.Data[count+1]
		count++
	}
	a.Data = a.Data[:a.Length-1]
	a.Length--
	return pop
}

/**
 * @description: 把该方法放进main方法里运行
 * @param {*}
 * @return {*}
 */
func Run() {
	a := &ArrayQueue{Data: []int{}, MaxLength: 100, Length: 0}
	for i := 0; i < 5; i++ {
		a.Push(i)
	}
	fmt.Println(a)
	for i := 0; i < 5; i++ {
		fmt.Println(a.Pop())
	}
	fmt.Println(a)
}
